<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>天气案例</title>
    <script src="js/vue.js"></script>
</head>
<body>
<div id="root">
    <h2>a:{{number.a}}</h2>
    <button @click="changeWeather">a+1</button>
</div>
<script>
    Vue.config.productionTip = false;
    const vm = new Vue({
        el: '#root',
        data: {
            number: {
                a: 1,
                b: 2,
            }
        },
        methods: {
            changeWeather() {
                this.number.a++;
            }
        },
        watch: {
            // 监视多级结构中某个属性变化
            'number.a': {
                handler() {
                    console.log('a改变了');
                }
            },
            // 监视多级结构中所有属性的变化
            number: {
                deep: true,
                handler() {
                    console.log('number改变了');
                }
            },
        }
    });
</script>
</body>
</html>